package core;

/**
 * @author Robbie Groenewoudt
 *
 */
public class Vector {

   public double x;
   public double y;

   // Constructor methods ....
   public Vector() {
      x = y = 0.0;
   }

   public Vector( double dX, double dY ) {
      this.x = dX;
      this.y = dY;
   }

   // Convert vector to a string ...
   public String toString() {
      return "Vector(" + x + ", " + y + ")";
   }

   // Compute magnitude of vector ....
   public double length() {
      return Math.sqrt ( x*x + y*y );
   }

   // Scale vector by a constant ...
   public Vector scale( double scaleFactor ) {
       Vector v2 = new Vector( this.x*scaleFactor, this.y*scaleFactor );
       return v2;
   }

   // Normalize a vectors length....
   public Vector normalize() {
      Vector v2 = new Vector();

      double length = length();
      if (length != 0) {
        v2.x = this.x/length;
        v2.y = this.y/length;
      }

      return v2;
   }   
}